package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.enums.OrderDeleteEnum;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizHot;
import com.member.shop.domain.SysBizMarketPage;
import com.member.shop.domain.SysBizMarketPageCategory;
import com.member.shop.service.ISysBizMarketPageCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【营销页面分类定义】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2025-02-14
 **/
@RestController
@RequestMapping("/shop/marketPageCategory")
public class SysBizMarketPageCategoryController extends BaseController {
    @Resource
    private ISysBizMarketPageCategoryService sysBizMarketPageCategoryService;

    /**
     * 查询营销页面分类定义列表
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPageCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizMarketPageCategory sysBizMarketPageCategory) {
        setTenantId(sysBizMarketPageCategory);
        startPage();
        LambdaQueryWrapper<SysBizMarketPageCategory> queryWrapper = new LambdaQueryWrapper<SysBizMarketPageCategory>();
        queryWrapper.eq(SysBizMarketPageCategory::getDeleted, OrderDeleteEnum.NOT_DELETE.getKey());
        queryWrapper.eq(sysBizMarketPageCategory.getTenantId()!=null,SysBizMarketPageCategory::getTenantId, sysBizMarketPageCategory.getTenantId());
        queryWrapper.eq(sysBizMarketPageCategory.getDisplayed()!=null,SysBizMarketPageCategory::getDisplayed, sysBizMarketPageCategory.getDisplayed());
        queryWrapper.eq(sysBizMarketPageCategory.getBussType()!=null,SysBizMarketPageCategory::getBussType, sysBizMarketPageCategory.getBussType());
        queryWrapper.orderByDesc(SysBizMarketPageCategory::getId);
        List<SysBizMarketPageCategory> list = sysBizMarketPageCategoryService.selectSysBizMarketPageCategoryList(queryWrapper);
        return getDataTable(list);
    }

    private void setTenantId(SysBizMarketPageCategory sysBizMarketPageCategory) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizMarketPageCategory.setTenantId(tenantId);
        }
    }

    /**
     * 导出营销页面分类定义列表
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPageCategory:export')")
    @Log(title = "营销页面分类定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizMarketPageCategory sysBizMarketPageCategory) {
        LambdaQueryWrapper<SysBizMarketPageCategory> queryWrapper = new LambdaQueryWrapper<SysBizMarketPageCategory>();
        List<SysBizMarketPageCategory> list = sysBizMarketPageCategoryService.selectSysBizMarketPageCategoryList(queryWrapper);
        ExcelUtil<SysBizMarketPageCategory> util = new ExcelUtil<SysBizMarketPageCategory>(SysBizMarketPageCategory.class);
        util.exportExcel(response, list, "营销页面分类定义数据");
    }

    /**
     * 获取营销页面分类定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPageCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizMarketPageCategoryService.selectSysBizMarketPageCategoryById(id));
    }

    /**
     * 新增营销页面分类定义
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPageCategory:add')")
    @Log(title = "营销页面分类定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizMarketPageCategory sysBizMarketPageCategory) {
        return toAjax(sysBizMarketPageCategoryService.insertSysBizMarketPageCategory(sysBizMarketPageCategory));
    }

    /**
     * 修改营销页面分类定义
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPageCategory:edit')")
    @Log(title = "营销页面分类定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizMarketPageCategory sysBizMarketPageCategory) {
        return toAjax(sysBizMarketPageCategoryService.updateSysBizMarketPageCategory(sysBizMarketPageCategory));
    }

    /**
     * 删除营销页面分类定义
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPageCategory:remove')")
    @Log(title = "营销页面分类定义", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(sysBizMarketPageCategoryService.deleteSysBizMarketPageCategoryById(id));
    }
}
